<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-yellow sidebar-mini">
<section class="content-header">
    <h1>领料申请查询</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" class="form-horizontal">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        流水号
                                    </label>
                                    <label class="control-label">
                                        <input name="orderNo" class="form-control" type="text" maxlength="255"
                                               value=""
                                               placeholder="请输入流水号"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        制单人
                                    </label>
                                    <label class="control-label">
                                        <input name="makeUserName" class="form-control" type="text" maxlength="255"
                                               value=""
                                               placeholder="请输入制单人"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">
                                        制单部门
                                    </label>
                                    <label class="control-label">
                                        <select name="makDeptId" class="form-control">
                                            <option value="" selected="selected">全部</option>
                                            <option th:each="item:${deptList}" th:value="${item.id}" th:text="${item.name}"></option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-left:0px;margin-right: 25px;">
                                    <label class="control-label">创建时间</label>
                                    <label class="control-label">
                                        <input type="text" class="form-control datepicker" name="startTime"
                                               readonly="readonly"/>
                                        <span> 至 </span>
                                        <input type="text" class="form-control datepicker" name="endTime"
                                               readonly="readonly"/></label>
                                </div>
                                <button id="btn-search" type="button" class="btn btn-success">
                                    搜索
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div id="toolbar" class="row">
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let table, tempTable, tempData = new Array(), currentProject;
    $(function () {
        /**
         * 加载列表
         */
        loadTable();
        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });
    });

    /**
     * 重新加载
     */
    function reloadTable() {
        js.table.refresh(table);
    }

    /**
     * 加载列表
     */
    function loadTable() {
        table = js.table.init({
            url: ctx + "materialRequisition/queryList",
            showColumns: true,
            showExport: true,
            columns: [
                {
                    checkbox: true,
                    width: '30px',
                    formatter: function (value, row, index) {
                        if (row.appStatus === 1 || row.appStatus === 4) {
                            return {disabled: false}
                        } else {
                            return {disabled: true}
                        }
                    }
                },
                {
                    title: '序号', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: '流水号', field: 'orderNo',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '制单人', field: 'makeUserName',width: '150',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '制单部门', field: 'makeDeptName',width: '200',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '创建时间', field: 'makCreateTime', width: '90',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }

                    }
                },
                {
                    title: '操作', width: '180',
                    formatter: function (value, row, index) {
                        let elements = new Array();
                        elements.push('<a class="btn btn-info btn-xs" href="/materialRequisition/view/' + row.id + '">查看</a>');
                        return elements.join('');
                    }
                }
            ]
        });
    }

    /**
     * 删除
     */
    function remove(id) {
        js.confirmPost({
            content: "尊敬的用户，您确认要删除此领料申请吗？",
            url: ctx + 'materialRequisition/delete',
            data: {
                id: id
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                } else {
                    js.modal.warning(result.msg);
                }
                js.table.refresh(table);
            }
        });
    }

    /**
     * 提交总调计划
     */
    function submit(idStr) {
        if (idStr === '') {
            let arr = js.table.selectColumns(table, "id");
            idStr = arr.join(',');
        }
        js.modal.confirm('尊敬的用户，您确定要提交此领料申请吗？', function () {
            js.post({
                url: ctx + 'materialRequisition/submit',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: {
                    idStr: idStr
                },
                async: true,                // 异步执行
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                    } else {
                        js.modal.warning(result.msg);
                    }
                    js.table.refresh(table);
                },
                error: function () {
                    js.modal.fail();
                }
            });
        });
    }

    /**
     * 重新加载
     */
    function reLoad() {
        js.table.refresh(table);
    }
</script>
</body>
</html>